package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Classinfo;
import cn.wolfcode.crm.query.ClassInfoQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IClassInfoService;
import cn.wolfcode.crm.service.IEmployeeService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/classInfo")
public class ClassInfoController {
    @Autowired
    private IClassInfoService classInfoService;
    @Autowired
    private IEmployeeService employeeService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") ClassInfoQueryObject qo){
        PageInfo result = classInfoService.query(qo);
        model.addAttribute("employees",employeeService.list());
        model.addAttribute("result",result);
        return "/classInfo/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Classinfo classinfo){
        if(classinfo.getId() != null){
            classInfoService.update(classinfo);
        }else {
            classInfoService.save(classinfo);
        }
        return new JsonResult();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id){
        classInfoService.delete(id);
        return new JsonResult();
    }

}
